package org.elip.stewiemaze.server.services;

import org.elip.stewiemaze.shared.entities.Player;


public class PlayerService {
	
	
	public static Player createPlayer(String nickname, String email, String password, Long scoreValue, boolean activated) {
		nickname = removeSpaces(nickname);
		Player player = new Player();
		player.setEmail(email);
		player.setNickname(nickname);
		player.setPassword(password);
		player.setFacebookUser("false");
		player.setAccessToken(null);
		player.setHighscore(scoreValue);
		player.setUserId(null);
		if (activated) {
			player.setActivated("true");
		}
		else {
			player.setActivated("false");
		}
		return player;
	}
	
	public static Player createFacebookPlayer(String nickname, String userId,String email ,Long scoreValue) {
		nickname = removeSpaces(nickname);
		Player player = new Player();
		player.setEmail(email);
		player.setNickname(nickname);
		player.setHighscore(scoreValue);
		player.setActivated("false");
		player.setFacebookUser("true");
		player.setUserId(userId);
		player.setAccessToken(null);
		player.setPassword(null);
		return player;
	}
	
	private static String removeSpaces(String s) {
		String[] elements = s.split(" ");
		if (elements.length == 1) return s;
		String result = "";
		for (String st : elements) {
			result += st;
		}
		return result;
	}

}
